﻿using System;
using System.ComponentModel;
using System.Windows;
using VisualWip.Core.Columns;
using VisualWip.Core.Utils;
using Application = VisualWip.Core.Application;

namespace VisualWip.PresentationModel.Uri
{
    public class UriColumnViewModel : ColumnViewModelBase
    {
        private readonly UriColumn _uriColumn;

        public UriColumnViewModel(Application application, UriColumn column, IColumnBuilder columnBuilder)
            : base(application, column, columnBuilder)
        {
            _uriColumn = column;
            application.PropertyChanged += ApplicationPropertyChanged;
        }

        public Visibility DesignMode
        {
            get
            {
                if (Application.IsDesignMode)
                    return Visibility.Hidden;

                return Visibility.Visible;
            }
        }

        public System.Uri Uri
        {
            get { return _uriColumn.Uri; }
        }

        protected override void ColumnRefreshDone(object sender, EventArgs e)
        {
            base.ColumnRefreshDone(sender, e);
            OnPropertyChanged(this, () => Uri);
        }

        private void ApplicationPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == PropertyHelper.Name(() => Application.IsDesignMode))
                OnPropertyChanged(this, () => DesignMode);
        }

        protected override void ColumnPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.ColumnPropertyChanged(sender, e);
            BubbleOnPropertyChanged(e, () => Uri);
        }
    }
}